package util;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


/**
 * UtilFeeder: Utility tools.
 * 
 * @author Li Jun Mulin
 * @version
 * 
 */

public class CommandLine {

	public static String validateNull(Object object) {
		if (object == null || object.equals("null")) {
			return "";
		} else {
			return object.toString();
		}
	}

	public static String exeExternalcommand(String command) {
		Process process;
		String line = "";
		try {
			process = Runtime.getRuntime().exec(command);
			process.waitFor();
			String message = "";
			if (process.exitValue() == 0) {
				try {
					BufferedReader in = new BufferedReader(
							new InputStreamReader(process.getInputStream()));
					while ((line = in.readLine()) != null) {
						message+=line+"\n";
					}
					return message;
				} catch (IOException e) {
					e.printStackTrace();
				}
			} else {
				return "Command Failure";
			}
		} catch (Exception e) {
			return "Exception: " + e.toString();
		}
		return line;
	}
}
